package com.ambow.store.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object obj = request.getSession().getAttribute("uid");
        if (obj == null){//说明用户没有登录过系统，重定向到login.html页面
            //说明用户没有登陆过系统
            response.sendRedirect("/web/login.html");
            //结束后调用
            return false;
        }
        //请求放行
        return true;
    }
}
